const BodyParser = require("body-parser");

const userList = [
  {
    username: "admin",
    password: "123",
    name: "张三",
    id: "1",
  },
  {
    username: "user",
    password: "123",
    name: "李四",
    id: "2",
  },
];

module.exports = (app) => {
  app.use(BodyParser.json());

  app.post("/api/login", (req, res) => {
    const { username, password } = req.body;

    const info = userList.find(item => item.password === password && item.username === username)

    if(info) {
        res.send({
            code: 1,
            msg: '登录成功'
        })
    } else {
        res.status(403)
        res.send({
            code: 0,
            msg: '登录失败，用户名或者密码不正确'
        })
    }

  });
};
